package com.mgzf.bs.uploadCenter.listener;

import com.mgzf.bs.uploadCenter.service.IkafkaService;
import com.mgzf.bs.uploadCenter.service.task.impl.GeneralUploadTask;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by mike on 18/1/18.
 */
@Component
public class KafkaMqListener implements ApplicationListener<ContextRefreshedEvent>{
    @Autowired
    private IkafkaService ikafkaService;
    protected static final Logger log = Logger.getLogger(KafkaMqListener.class);

    private ExecutorService executorService = Executors.newCachedThreadPool();

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        System.out.println("123123");
        log.info("kafka监听开始.........");
        init();

    }
    private void init(){
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                ikafkaService.receive("test",new GeneralUploadTask());
            }
        });
    };
}
